package com.tecniplast.selene.factory;

import java.util.HashMap;
import java.util.Map;

import com.tecniplast.selene.pojo.AppInface;
import com.tecniplast.selene.pojo.Syscode;
@SuppressWarnings("rawtypes")
public class CacheFactory {  
    
    private static CacheFactory cacheFactory = null;  
      
    //缓存已经创建的Map对象  
    
	private Map<String,Map> factoryMap = new HashMap<String,Map>();  
      
    //单例模式  
    private CacheFactory(){  
    }  
      
    //使用“懒加载”的单例模式  
    public static CacheFactory getInstance(){  
        if(cacheFactory == null){  
            cacheFactory = new CacheFactory();  
        }  
        return cacheFactory;  
    }  
      
    /** 
     * 创建key为cachName的Map对象 
     * @param cachName 
     * @return 
     */  
    @SuppressWarnings("unchecked")
	public Map<String,Object> createCache(String cachName){  
        Map map = new HashMap<String,Object>();  
        factoryMap.put(cachName, map);  
        return map;  
    }  
      
    /** 
     * 判断是否存在key为cachName的map 
     * @param cachName 
     * @return 
     */  
    public boolean isExist(String cachName){  
        if(factoryMap.containsKey(cachName)){  
            return true;  
        }  
        return false;  
    }  
      
    /** 
     * 获取key为cachName的map对象 
     * @param cachName 
     * @return 
     */  
    public Map getMapByKey(String cachName){  
        if(factoryMap.containsKey(cachName)){  
            return factoryMap.get(cachName);  
        }  
        return null;  
    }  
    
    
    /** 
     * 根据父key 子key  获取参数表代码值
     * @param cachName 
     * @return 
     */  
    @SuppressWarnings("unchecked")
	public String getMapByKey(String cachName,String key){  
        if(factoryMap.containsKey(cachName)){  
            Map<String,Object> map =  factoryMap.get(cachName);  
            Syscode scode = (Syscode)map.get(key);
            return scode.getValue();
        }  
        return null;  
    }  
    
    /** 
     * 根据父key 子key  获取参数表代码值
     * @param cachName 
     * @return 
     */  
    @SuppressWarnings("unchecked")
	public String getAppInfaceMapByType(String cachName,String key){  
        if(factoryMap.containsKey(cachName)){  
            Map<String,Object> map =  factoryMap.get(cachName);  
            AppInface scode = (AppInface)map.get(key);
            return scode.getUrl();
        }  
        return null;  
    }
      
}  
